package com.service.impl;

import com.constant.Constant;
import com.dao.ChapterMapper;
import com.entity.Chapter;
import com.constant.Constant;
import com.dao.ChapterMapper;
import com.entity.Chapter;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.service.ChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import com.vo.ChapterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import javax.servlet.http.HttpServletRequest;
import java.util.List;


@Service
public class ChapterServiceImpl implements ChapterService {
    @Autowired
    ChapterMapper chapterMapper;

    @Override
    public String selectChaptepByCourseId(Integer courseID, HttpServletRequest request) {
        System.out.println("courseId=" + courseID);
        List<Chapter> chapters = chapterMapper.selectChaptepByCourseId(courseID);
        request.setAttribute(Constant.CHAPTERS, chapters);
        System.out.println("========================");
        System.out.println(chapters);
        return "front/front_course";
    }


    //吴彬彬  查询课程章节
    @Override
    public PageInfo loadChapter(ChapterVo chapterVo) {
        PageHelper.startPage(chapterVo.getPageNo(), Constant.PAGE_SIZE);
        List<Chapter> chapters = chapterMapper.loadChapter(chapterVo);
        PageInfo info = new PageInfo(chapters);
        return info;
    }

    //吴彬彬  修改课程章节状态 简介  名字
    @Override
    public int modifyChapter(Chapter chapter) {

        return chapterMapper.modifyChapter(chapter);
    }

    //吴彬彬    增加
    @Override
    public int addChapter(Chapter chapter) {

        return chapterMapper.addChapter(chapter);
    }

    @Override
    public List<Chapter> selectAllSTitle() {
        return chapterMapper.selectAllSTitle();
    }

    //吴彬彬   显示修改前的内容
    @Override
    public Chapter showToModify(Integer id) {
        return chapterMapper.showToModify(id);
    }


}
